import { IConfirmUtil, ConfirmParams } from '@ibiz-template/runtime';
import { ElMessageBox } from 'element-plus';

/**
 * 确认操作框
 *
 * @author chitanda
 * @date 2022-08-17 16:08:52
 * @export
 * @class ConfirmUtil
 * @implements {IConfirmUtil}
 */
export class ConfirmUtil implements IConfirmUtil {
  async info(params: ConfirmParams): Promise<boolean> {
    return new Promise(resolve => {
      ElMessageBox.confirm(params.desc, params.title, {
        customClass: 'confirm-info',
        ...params.options,
      })
        .then(() => resolve(true))
        .catch(() => resolve(false));
    });
  }

  async success(params: ConfirmParams): Promise<boolean> {
    return new Promise(resolve => {
      ElMessageBox.confirm(params.desc, params.title, {
        customClass: 'confirm-success',
        ...params.options,
      })
        .then(() => resolve(true))
        .catch(() => resolve(false));
    });
  }

  async warning(params: ConfirmParams): Promise<boolean> {
    return new Promise(resolve => {
      ElMessageBox.confirm(params.desc, params.title, {
        customClass: 'confirm-warning',
        ...params.options,
      })
        .then(() => resolve(true))
        .catch(() => resolve(false));
    });
  }

  async error(params: ConfirmParams): Promise<boolean> {
    return new Promise(resolve => {
      ElMessageBox.confirm(params.desc, params.title, {
        customClass: 'confirm-error',
        ...params.options,
      })
        .then(() => resolve(true))
        .catch(() => resolve(false));
    });
  }
}
